package controllers.commands
{
	import com.google.maps.Map;
	
	import controllers.commands.base.ICommand;
	import controllers.managers.UIInstanceManager;
	
	import model.context.TrackerContext;
	
	import view.MapCanvas;
	
	/**
	 * 清空地图
	 **/
	public class ClearMapCommand implements ICommand
	{
		private var context:TrackerContext;
		
		public function ClearMapCommand(view:MapCanvas=null)
		{
			this.context = new TrackerContext();
			if ( view == null )
			{
				var map:MapCanvas = MapCanvas(UIInstanceManager.getUI(MapCanvas.NAME));
				view = map;
			}
			this.context.mapCanvas = view;
		}
		
		public function setContext(context:Object):void
		{
			this.context = TrackerContext(context);
		}
		
		/**
		 * 清空画布
		 **/
		public function execute():void
		{
			var v:MapCanvas=null;
			if(this.context != null && this.context.mapCanvas != null)
			{
				v = context.mapCanvas;
				var map:Map = v.map;
				if(map != null)
				{
					map.clearOverlays();
				}
			}
		}
	}
}